package online.hxstar.cloud.gateway.dynamic;

import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * 查询网关的路由信息
 *
 * @author xinghu
 * @date 2019/9/6 12:18 下午
 */
@RestController
@RequestMapping("/route")
public class DynamicRouteController {

	private final RouteDefinitionLocator routeDefinitionLocator;

	public DynamicRouteController(
			RouteDefinitionLocator routeDefinitionLocator) {
		this.routeDefinitionLocator = routeDefinitionLocator;
	}

	/**
	 * 获取网关所有的路由信息
	 *
	 * @return 路由信息
	 */
	@RequestMapping("/routes")
	public Flux<RouteDefinition> getRouteDefinitions() {
		return routeDefinitionLocator.getRouteDefinitions();
	}
}
